package dearchenpush.good.com.qianfanlive.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import dearchenpush.good.com.qianfanlive.R;
import dearchenpush.good.com.qianfanlive.modules.live.bean.LiveTwoBean;
import dearchenpush.good.com.qianfanlive.url.UrlConfigs;
import io.vov.vitamio.Vitamio;
import io.vov.vitamio.widget.VideoView;
import okhttp3.Call;

public class LiveActivity extends AppCompatActivity {
    TextView textView;
    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live);
        Vitamio.isInitialized(this);
        initView();

        Intent intent = getIntent();
        int tag = intent.getIntExtra("tag", -1);
        String roomid = intent.getStringExtra("roomid");
        String livetwo = String.format(UrlConfigs.LIVE_TWO, roomid);
        Log.e("==========>", "onCreate: "+livetwo );
        OkHttpUtils.get().url(livetwo).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                Gson gson = new Gson();
                LiveTwoBean liveTwoBean = gson.fromJson(response, LiveTwoBean.class);
                String rUrl = liveTwoBean.getMessage().getRUrl();
                String livePath = rUrl.substring(0, rUrl.indexOf("?"));


videoView.setVideoPath(livePath);
             //   videoView.setVideoPath("http://200023900.vod.myqcloud.com/200023900_46e94876a8d74ed09b3f4a80468a76d0.f240.av.m3u8");

                //videoView.setVideoPath("http://v.ngb.qf.56.com/live/7722926_1475127856561?only-audio=1&wsSecret=c76c5d65ded91fe4ce6b61320e7a316f&wsTime=57ECD8AD&cid=1&ver=ngb&cip=ngb&get_url=6");
                videoView.start();

            }
        });



       // String path = "http://v.ngb.qf.56.com/live/7722926_1475127856561?only-audio=1&wsSecret=c76c5d65ded91fe4ce6b61320e7a316f&wsTime=57ECD8AD&cid=1&ver=ngb&cip=ngb&get_url=6";

    }

    private void initView() {
        videoView = (VideoView) findViewById(R.id.activity_live_vitamo);
    }
}
